home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Environments / Small Eiffel 0.4.8 / lib_rand / std_rand.e < prev   
Text File  |  1997-04-13  |  1KB  |  87 lines

  1. -- Part of SmallEiffel -- Read DISCLAIMER file -- Copyright (C) 
  2. -- Dominique COLNET and Suzanne COLLIN -- colnet@loria.fr
  3. --
  4. class STD_RAND
  5.    -- Press' standard generator, which uses the minimal standard 
  6.    -- and then uses shuffling to break up short order corelations.
  7.    
  8. inherit
  9.    MIN_STAND
  10.       redefine with_seed, next
  11.       select with_seed, next
  12.       end;
  13.    MIN_STAND
  14.       rename
  15.      next as min_next
  16.       export
  17.      {NONE} min_next
  18.       redefine
  19.      last_integer, last_real
  20.       end;
  21.  
  22. creation make, with_seed
  23.  
  24. feature {NONE}
  25.    
  26.    iv: ARRAY[INTEGER];
  27.  
  28.    ntab: INTEGER is 32;
  29.  
  30.    iy: INTEGER;
  31.  
  32. feature {NONE}
  33.  
  34.    with_seed(seed_value:INTEGER) is
  35.       require
  36.      valid_seed: seed_value > 0 and seed_value < im
  37.       local
  38.      i: INTEGER;
  39.       do
  40.      seed := seed_value;
  41.      min_next;
  42.      !!iv.make(1,ntab);
  43.      from 
  44.         i := 1;
  45.      until 
  46.         i > 7
  47.      loop
  48.         min_next;
  49.         i := i + 1;
  50.      end;
  51.      from
  52.         i := ntab;
  53.      until
  54.         i = 0
  55.      loop
  56.         iv.put(seed,i);
  57.         min_next;
  58.         i := i - 1;
  59.      end
  60.      iy := iv.item(1);
  61.      next;
  62.       end
  63.  
  64. feature
  65.  
  66.    next is
  67.       local
  68.      tmp:INTEGER
  69.       do
  70.      tmp := iy \\ ntab + 1;
  71.      min_next;
  72.      iy := iv.item(tmp);
  73.      iv.put(seed,tmp);
  74.       end
  75.  
  76.    last_integer(n:INTEGER):INTEGER is
  77.       do
  78.      Result := iy \\ n + 1;
  79.       end
  80.  
  81.    last_real:REAL is
  82.       do
  83.      Result := (iy / im).to_real;
  84.       end
  85.  
  86. end
  87.